import * as actionTypes from './constants'
import {
    getHotwordsRequest,
    getSuggestListRequest,
    // getResultSongsListRequest
} from '@/api/request'

// 供 异步请求 action 用，不 export
const changeHotwords = (data) => ({
    type: actionTypes.SET_HOT_KEYWOEDS,
    data
})
const changeSuggestList = (data) => ({
    type: actionTypes.SET_SUGGEST_LIST,
    data
})
const changeResultSongs = (data) => ({
    type: actionTypes.SET_SONGS_LIST,
    data
})
export const changeEnterLoading = (data) => ({
    type: actionTypes.SET_ENTER_LOADING,
    data
})
export const getHotwords = () => {
    return (dispatch) => {
        getHotwordsRequest()
            .then(data => {
                // console.log(data.data.data);
                // let list = data.result.hots;
                // const action = changeHotwords(data.data.data)
                dispatch(changeHotwords(data.data.data))
            })
    }
}
export const getSuggestList = (query) => {
    return dispatch => {
        // console.log(query);
        getSuggestListRequest(query)
            .then(data => {
                // console.log(data.data.data.tag);
                if (!data) return;
                let res = data.data.data.tag || [];
                dispatch(changeSuggestList(res))
                // dispatch(changeEnterLoading(false))
            })
        // getResultSongsListRequest(query)
        //     .then(data => {
        //         if (!data) return;
        //         let res = data.result.songs || [];
        //         dispatch(changeResultSongs(res))
        //         dispatch(changeEnterLoading(false))
        //     })
    }
}